package com.catmiao.ai.controller;


import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.chat.response.ChatResponse;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/llm")
public class ChatTokenController {

    @Resource
    private ChatModel chatModel;

    @GetMapping("/token")
    public String chat(@RequestParam(value = "prompt",defaultValue = "你是谁") String prompt){
        ChatResponse result = chatModel.chat(UserMessage.from(prompt));

        System.out.println("【robot】：" + result.aiMessage().text());
        System.out.println("【robot】：" + result.tokenUsage());



        return result.aiMessage().text();
    }
}
